import java.util.Stack;

public class test {

    //栈的压入弹出序列
    public static boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while(j < popA.length && !stack.empty() && stack.peek()==popA[j]){
                j++;
                stack.pop();
            }
        }
        return stack.empty();
    }

    // 逆波兰表达式(后缀表达式)
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (String x:tokens){
            if (!isOperation(x)) {
                stack.push(Integer.parseInt(x));
            } else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (x){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    public boolean isOperation(String s){
        if(s.equals("+") || s.equals("-") ||s.equals("*") ||s.equals("/")){
            return true;
        }
        return false;
    }
    // 有效的括号
    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch=='(' || ch=='{' || ch=='['){
               stack.push(ch);
            }else {
                //说明是右括号
                if(stack.empty()){
                    //为空-> 右括号多
                    return false;
                }
                char top = stack.peek();
                if(ch==')'&&top=='(' || ch=='}'&&top=='{' || ch==']'&&top=='['){
                    //当前括号是匹配的 就出栈
                    stack.pop();
                }else{
                    //不匹配
                    return false;
                }
            }
        }
        if(stack.empty()){
            return true;
        }else {
            return false;
        }
    }



    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        //myStack.pop();
       /* myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        myStack.push(5);
        System.out.println("3的下标为:"+myStack.search(3));
        System.out.println("弹出栈顶元素:"+myStack.pop());
        System.out.println("栈顶元素为:"+myStack.peek());
        System.out.println("压栈(入栈):"+myStack.push(6));
        System.out.println("栈顶元素为:"+myStack.peek());
        System.out.println("栈是否为空:"+myStack.empty());
        System.out.println("栈是否满了:"+myStack.isFull());*/
        int[] a = {1,2,3,4,5};
        int[] b = {4,5,3,2,1};
        System.out.println(IsPopOrder(a, b));


    }
}
